import {createStore,applyMiddleware} from 'redux'

import logger from 'redux-logger'
import thunk from 'redux-thunk'
import reducer from './reducer'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'


const persistedReducer = persistReducer({key:'root',storage},reducer)
//创建一个唯一的store
// 获取store里的state   store.getState()
// 修改store里的state    store.dispatch()
//监听store里的state     store.subscribe()

// export default createStore(reducer,applyMiddleware(thunk,logger))


var logger2 = function({dispatch, getState}){
    return function(next){
        return function(action){
            console.log('logger2',getState());
            return next(action)//移交控制器给下一个中间件
        }
    } 
}


let store = createStore( persistedReducer, applyMiddleware(logger2,thunk, logger) )

let persistor = persistStore(store);

export {
    store,
    persistor
} 